﻿/*  ----------------------------------------------------------------------------
 *  SysServer
 *  ----------------------------------------------------------------------------
 *  File:       IDataProtocol.cs
 *  Creater:     SEEN\MistSeen
 *  ----------------------------------------------------------------------------
 *  $Date: 2010-09-06 10:36:01 +0000 (Mon, 06 Sep 2010) $
 *  $Rev: 15 $
 *  $Author: ScorDeity $
 *  $URL: http://sysserver.googlecode.com/svn/trunk/src/SysServer/NetWrok/IDataProtocol.cs $
 *  $Id: IDataProtocol.cs 15 2010-09-06 10:36:01Z ScorDeity $
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SysServer.NetWrok
{
    /// <summary>
    /// 抽象通信协议格式的基础接口。
    /// </summary>
    public interface IDataProtocol
    {
        /// <summary>
        ///将流解析为对象
        /// </summary>
        /// <param name="data"></param>
        /// <param name="offset"></param>
        void Fill(Byte[] data, int offset);
        /// <summary>
        /// 解析后对象的流长度.不是整个协议的长度
        /// </summary>
        /// <returns></returns>
        int GetStreamLength();
        /// <summary>
        /// 将对象转化为流
        /// </summary>
        /// <returns></returns>
        Byte[] AsStream();
        /// <summary>
        /// 将转化的结果流写到指定的buff中，这个方法是必须的，否则就会遇到很多需要拷贝缓冲区的操作，这将严重的损害运行的效率。
        /// </summary>
        /// <param name="buffer"></param>
        /// <param name="offset"></param>
        void AsStream(Byte[] buffer, int offset);
    }
}